From: Colin Walters Date: Wed, 4 Nov 2009 20:48:26 +0000 (-0500) Subject: [StThemeNode] Don't give negative width/height for content boxes X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~10690 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=dcd7762253e959638dfcfdabc8881a7b5a9e632f;p=gnome-shell.git [StThemeNode] Don't give negative width/height for content boxes If the space we're allocated is too small for our border + padding constraints, don't give negative allocations to callers. Squash to zero. It isn't really useful for callers to get negative content sizes, and certainly breaks most allocation code. https://bugzilla.gnome.org/show_bug.cgi?id=600734 --- diff --git a/src/st/st-theme-node.c b/src/st/st-theme-node.c index 0aba8b6d5..cebd1afde 100644 --- a/src/st/st-theme-node.c +++ b/src/st/st-theme-node.c @@ -2211,14 +2211,33 @@ st_theme_node_get_content_box (StThemeNode *node, const ClutterActorBox *allocation, ClutterActorBox *content_box) { + double noncontent_left, noncontent_top, noncontent_right, noncontent_bottom; + double avail_width, avail_height, content_width, content_height; + g_return_if_fail (ST_IS_THEME_NODE (node)); ensure_geometry (node); - content_box->x1 = (int)(0.5 + node->border_width[ST_SIDE_LEFT]) + node->padding[ST_SIDE_LEFT]; - content_box->y1 = (int)(0.5 + node->border_width[ST_SIDE_TOP]) + node->padding[ST_SIDE_TOP]; - content_box->x2 = allocation->x2 - allocation->x1 - ((int)(0.5 + node->border_width[ST_SIDE_RIGHT]) + node->padding[ST_SIDE_RIGHT]); - content_box->y2 = allocation->y2 - allocation->y1 - ((int)(0.5 + node->border_width[ST_SIDE_BOTTOM]) + node->padding[ST_SIDE_BOTTOM]); + avail_width = allocation->x2 - allocation->x1; + avail_height = allocation->y2 - allocation->y1; + + noncontent_left = node->border_width[ST_SIDE_LEFT] + node->padding[ST_SIDE_LEFT]; + noncontent_top = node->border_width[ST_SIDE_TOP] + node->padding[ST_SIDE_TOP]; + noncontent_right = node->border_width[ST_SIDE_RIGHT] + node->padding[ST_SIDE_RIGHT]; + noncontent_bottom = node->border_width[ST_SIDE_BOTTOM] + node->padding[ST_SIDE_BOTTOM]; + + content_box->x1 = (int)(0.5 + noncontent_left); + content_box->y1 = (int)(0.5 + noncontent_top); + + content_width = avail_width - noncontent_left - noncontent_right; + if (content_width < 0) + content_width = 0; + content_height = avail_height - noncontent_top - noncontent_bottom; + if (content_height < 0) + content_height = 0; + + content_box->x2 = (int)(0.5 + content_box->x1 + content_width); + content_box->y2 = (int)(0.5 + content_box->y1 + content_height); }